# -*- coding: utf-8 -*-
# @Time    : 2016-12-07 10:46
# @Author  : wzb<wangzhibin_x@foxmail.com>
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import csv
import pandas
import seaborn
from copy import deepcopy
from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
import math


def strip_first_col(fname, delimiter=None):
    with open(fname, 'r') as fin:
     for line in fin:
      try:
       yield line.split(delimiter, 1)[1]
      except IndexError:
       continue


filename='BatteryLog.csv'
#filename='testdata2021/step/acc_20210908203517_wzb_上楼梯_下楼梯.txt'
#filename='testdata2021/step/acc_20210922163411_wzb_杂乱甩手.txt'


my_matrix = np.loadtxt(strip_first_col(filename,","),delimiter=",",skiprows=0)

#print(my_matrix)




level=my_matrix[:,0]
vol=my_matrix[:,2]

t=np.arange(0,len(level),1)

fig=plt.figure(figsize=(8,4))


'''
#print(t)
y_filter=np.arange(0,len(y),1)
x_filter=np.arange(0,len(y),1)
z_filter=np.arange(0,len(y),1)
xyz_filter=np.arange(0,len(y),1)
xyz_filter2=np.arange(0,len(y),1)

p_filter=np.arange(0,len(y),1)
for i in t:
    if(i<7):
        y_filter[i]=y[i]
        x_filter[i] = x[i]
        z_filter[i] = z[i]
        xyz_filter[i]=xyz[i]

    if(i>=7):

        x_filter[i]=x[i]*0.0779+x[i-1]*0.1124+x[i-2]*0.1587+x[i-3]*0.1867+x[i-4]*0.1867+x[i-5]*0.1587+x[i-6]*0.1124+x[i-7]*0.0779
#        print(x[i])
        y_filter[i] = y[i] * 0.0779 + y[i - 1] * 0.1124 + y[i - 2] * 0.1587 + y[i - 3] * 0.1867 + y[i - 4] * 0.1867 + y[
                                                                                                               i - 5] * 0.1587 + \
               y[i - 6] * 0.1124 + y[i - 7] * 0.0779
        z_filter[i] = z[i] * 0.0779 + z[i - 1] * 0.1124 + z[i - 2] * 0.1587 + z[i - 3] * 0.1867 + z[i - 4] * 0.1867 + z[
                                                                                                               i - 5] * 0.1587 + \
               z[i - 6] * 0.1124 + z[i - 7] * 0.0779
        xyz_filter[i] = xyz[i] * 0.0779 + xyz[i - 1] * 0.1124 + xyz[i - 2] * 0.1587 + xyz[i - 3] * 0.1867 + xyz[i - 4] * 0.1867 + xyz[
                                                                                                                      i - 5] * 0.1587 + \
                        xyz[i - 6] * 0.1124 + xyz[i - 7] * 0.0779

for i in t:
        if (i < 7):
            xyz_filter2[i] = xyz_filter[i]
        if (i >= 7):
            xyz_filter2[i] = xyz_filter[i] * 0.0779 + xyz_filter[i - 1] * 0.1124 + xyz_filter[i - 2] * 0.1587 + xyz_filter[i - 3] * 0.1867 + xyz_filter[
                                                                                                                    i - 4] * 0.1867 + \
                             xyz_filter[
                                i - 5] * 0.1587 + \
                             xyz_filter[i - 6] * 0.1124 + xyz_filter[i - 7] * 0.0779

# print(y)
'''
# test


print("################################################")



#y=y*(-1)
#x=abs(x)
#y=abs(y)
#
#plt.plot(t, y, label="$a-y$",color="black",linewidth=0.5)
#plt.plot(t, x, label="$a-x$",color="blue",linewidth=0.5)
#plt.plot(t, z, label="$a-z$",color="green",linewidth=0.5)
#plt.plot(t, my_matrix[:,4], label="$gyr-x$",color="y",linewidth=1)
#plt.plot(t, my_matrix[:,5], label="$gyr-y$",color="c",linewidth=1)
#plt.plot(t, my_matrix[:,6], label="$gyr-z$",color="b",linewidth=1)
#plt.plot(test_data[:,0],test_data[:,1] , label="$track$",color="red",linewidth=1)

#plt.plot(testx,testy , label="$track1$",color="blue",linewidth=1)
#qiaodan
#plt.plot(test_data[:,0][0:50],test_data[:,1][0:50] , label="$track$",color="blue",linewidth=1)
#plt.plot(test_data[:,0][50:100],test_data[:,1][50:100] , label="$track$",color="red",linewidth=1)
#plt.plot(test_data[:,0][100:150],test_data[:,1][100:150] , label="$track$",color="green",linewidth=1)
#plt.plot(test_data[:,0][150:200],test_data[:,1][150:200] , label="$track$",color="y",linewidth=1)
#end
#axl = fig.add_subplot(111)
#axl.scatter(test_data[:,0],test_data[:,1],s=100,c='r',marker='o')

#plt.plot(t, (x_filter*y_filter)/10, label="$x*y$",color="blue",linewidth=0.5)
#plt.plot(t, x_filter, label="$a-x$",color="blue",linewidth=0.5)
#plt.plot(t, z_filter, label="$a-z$",color="blue",linewidth=0.5)

#plt.plot(t, gx, label="$gx$",color="red",linewidth=0.5)
#plt.plot(t, gy, label="$gy$",color="blue",linewidth=0.5)
#plt.plot(t, gz, label="$gz$",color="black",linewidth=1)

#plt.plot(t, vol/100, label="$vol$",color="red",linewidth=2.0)
#plt.plot(t, (p_filter+85)*10, label="$pfilter$",color="black",linewidth=0.5)
#plt.plot(t, xyz, label="$xyz$",color="blue",linewidth=0.5)
#plt.plot(t, y, label="$y$",color="green",linewidth=0.5)
#plt.plot(t, z, label="$z$",color="black",linewidth=0.5)
plt.plot(t, level, label="$level$",color="blue",linewidth=2.0)
plt.xlabel("Time(s)")
plt.ylabel("v")
plt.title(filename)
#plt.ylim(-20, 20)
axl = fig.add_subplot(111)
axl.scatter(t,level,s=100,c='r',marker='o')

plt.xlabel(t)
#plt.xticks(range(0,88))
#plt.yticks(range((int)(min(y)),(int)(max(y))))

plt.legend()
plt.show()









